﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Samurai.Client.Commands;
using System.ComponentModel;

namespace Samurai.Client.DataContexts
{
    public abstract class ADataContext : INotifyPropertyChanged
    {
        public abstract void OnLoaded();

        private bool _isWaiting;
        public bool IsWaiting
        {
            get { return _isWaiting; }
            set
            {
                _isWaiting = value;
                OnPropertyChanged("IsWaiting");
            }
        }

        protected void TakeLongOperationAction(CommandBase command)
        {
            command.LongOperationStarted = (() => this.IsWaiting = true);
            command.LongOperationFinished = (() => this.IsWaiting = false);
        }

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }


}
